<!--用户管理页-->
<template>
  <div style="height: 6vh;background-color:#fff;padding:10px 20px;">
    <span style="line-height:60px;font-size: 20px;">员工管理</span>
  </div>
  <!-- 员工搜索卡片 -->
  <el-card style="margin: 20px;height: 70px; color: #42b983">
    <el-form :inline="true">
      <el-form-item label="员工搜索">
        <el-input placeholder="请输入员工用户名" style="width: 220px;"
                  v-model="searchStaffForm.name"
                  @keydown.enter="loadStaff"></el-input>
      </el-form-item>
      <el-form-item label="员工手机号">
        <el-input placeholder="请输入员工手机号" style="width: 220px;"
                  v-model="searchStaffForm.phone"
                  @keydown.enter="loadStaff"></el-input>
      </el-form-item>
      <el-form-item label="员工状态">
        <el-select
            v-model="searchStaffForm.status"
            clearable
            placeholder="请选择员工状态"
            style="width: 240px"
        >
          <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button @click="resetSearch">重置</el-button>
        <el-button type="primary" @click="loadStaff"  style="background-color: #42b983">搜索</el-button>
      </el-form-item>
    </el-form>
  </el-card>

  <!-- 员工列表表格卡片 -->
  <el-card style="margin: 20px;">
    <el-table :data="staffArr">
      <el-table-column type="index" label="编号" width="80" align="center"></el-table-column>
      <el-table-column label="用户名" prop="username" align="center"></el-table-column>
      <el-table-column label="手机号" prop="phone" align="center"></el-table-column>
      <el-table-column label="年龄" prop="age" align="center"></el-table-column>
      <el-table-column label="性别" prop="gender" align="center"
                       :formatter="vehicleTypeFormatter"   ></el-table-column>
      <el-table-column label="员工状态" prop="status" align="center"></el-table-column>
      <el-table-column label="加入时间" prop="createTime" align="center"></el-table-column>
      <el-table-column label="操作" align="center">
        <template #default="scope">
          <el-button link type="primary"  style="color: #42b983">
            <!--                      @click="deleteUser(scope.row.id)"-->
            删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </el-card>
</template>
<script setup>
import axios from "axios";
import {onMounted ,ref} from "vue";
import {ElMessage} from "element-plus";
import qs from "qs";

//定义对象来保存员工查询的条件
const searchStaffForm = ref({name:'',phone:'',status:''});
//定义对象保存查询到的员工表格数据
const staffArr = ref([]);
//定义加载员工列表的方法
const loadStaff = ()=>{
  let data = qs.stringify(searchStaffForm.value);
  //如果有查询条件,就根据条件查,没有条件默认查全部数据
  axios.get(BASE_URL+'/v1/user/select?'+data)
      .then((response)=>{//回调函数,处理响应数据
        if(response.data.code===2000){//后端返回的状态码是2000说明成功了
          staffArr.value = response.data.data;//把请求回来的数据装到绑定表格的数组中
          console.log(staffArr.value);
        }else{
          ElMessage.error(response.data.msg);
        }
      })
}
const options = [
  {
    value: '1',
    label: '在岗',
  },
  {
    value: '2',
    label: '休假',
  }
]
//页面一加载完毕,立即执行
onMounted(()=>{
  loadStaff();
})

//重置搜索
const resetSearch = ()=>{
  //清空之前的搜索内容
  searchStaffForm.value = {};
  //重新加载所有的用户数据
  loadStaff();
}
// 对性别进行文字转换
const vehicleTypeFormatter = (row, column, cellValue,index)=>{

  if(cellValue == 1){
    cellValue = '男';
  }else if(cellValue == 0){
    cellValue = '女';
  }
  return cellValue;
}
</script>

<style scoped>

</style>